package com.h3c.nem.config.mq;

import com.h3c.nem.config.mq.consumer.EmailAckReceiver;
import com.h3c.nem.config.mq.consumer.EsignAckReceiver;
import lombok.AllArgsConstructor;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 学历信息控制层
 *
 * @author chenyifan
 * @since 2022-06-20 11:42:52
 */
@Configuration
@AllArgsConstructor
public class MessageListenerConfig {


    private final CachingConnectionFactory connectionFactory;

    private final EsignAckReceiver esignAckReceiver;

    private final EmailAckReceiver emailAckReceiver;

    private static final String NEM_EMAIL_QUEUE_NAME = "nem_email_queue";

    private static final String NEM_SIGN_QUEUE_NAME = "nem_sign_queue";

    @Bean("EsignMessageListenerContainer")
    public SimpleMessageListenerContainer esignMessageListenerContainer() {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
        container.setConcurrentConsumers(1);
        container.setMaxConcurrentConsumers(5);
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        container.setQueueNames(NEM_SIGN_QUEUE_NAME);
        container.setMessageListener(esignAckReceiver);
        return container;
    }

    @Bean("emailMessageListenerContainer")
    public SimpleMessageListenerContainer emailMessageListenerContainer() {
        SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(connectionFactory);
        container.setConcurrentConsumers(1);
        container.setMaxConcurrentConsumers(5);
        container.setAcknowledgeMode(AcknowledgeMode.MANUAL);
        container.setQueueNames(NEM_EMAIL_QUEUE_NAME);
        container.setMessageListener(emailAckReceiver);
        return container;
    }

}